import 'dart:convert';
import 'dart:io';

import 'package:flutter_test/flutter_test.dart';
import 'package:im_app/im/pojo/Enums.dart';
import 'package:im_app/im/service/LoginService.dart';
import 'package:im_app/im/socket/dto/business/Login.dart';
import 'package:im_app/im/socket/dto/business/PullData2.dart';
import 'package:im_app/im/socket/dto/business/SendData.dart';
import 'package:im_app/im/socket/service/RpcSendDataService.dart';
import 'package:logger/logger.dart';

import '../BaseImTest.dart';

void main() {
  test("test pull groupInfo", () async {
    var imWebSocket = await BaseImTest.initWebSocket();
    var dataSource = await BaseImTest.initDb();
    var logger = Logger();
    logger.i("websocket run");

    LoginReq loginReq = LoginReq(userId: "张飞", password: "123456", machineCode: "demo",
        tenantCode: "0002", terminalType: "android");
    logger.i("login json: " + loginReq.toJson().toString());
    LoginService loginService = LoginService();
    LoginResp? loginResp = await loginService.login(loginReq, LoginType.password);
    logger.i("login success result : " + jsonEncode(loginResp));

    var rpcGroupSerivice = new RpcGroupService();

    var groupInfoReq = new GroupInfoReq(groupId: '58cb5c77-972a-4fc3-b67b-304db926c858');
    var groupInfoItem = await rpcGroupSerivice.pullGroupInfo(groupInfoReq);
    logger.i("configData: " + jsonEncode(groupInfoItem));

    var duration = const Duration(seconds: 10);
    logger.i('Start sleeping');
    sleep(duration);
    dataSource.close();
    // imWebSocket?.close();
  }, timeout: Timeout.factor(3));
}